﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.utils {
    import reprise.data.*;

    public class StringUtil {

        public static const CHAR_WHITESPACE:Array = [" ", "\t", "\n", "\r"];
        public static const CASEINSENSITIVE_SEARCH:int = 1;
        public static const BACKWARDS_SEARCH:int = 2;

        public static function ucFirst(_arg1:String):String{
            return ((_arg1.charAt(0).toUpperCase() + _arg1.substr(1)));
        }
        public static function indexOfStringInRange(_arg1:String, _arg2:String, _arg3:Range=null, _arg4:int=0):int{
            if ((_arg4 & CASEINSENSITIVE_SEARCH)){
                _arg1 = _arg1.toLowerCase();
                _arg2 = _arg2.toLowerCase();
            };
            var _local5:String = _arg1.substr(_arg3.location, _arg3.length);
            var _local6:int = ((_arg4 & BACKWARDS_SEARCH)) ? _local5.lastIndexOf(_arg2) : _local5.indexOf(_arg2);
            if (_local6 == -1){
                return (-1);
            };
            return ((_arg3.location + _local6));
        }
        public static function isWhitespace(_arg1:String):Boolean{
            var _local2:int = _arg1.length;
            while (_local2--) {
                if (" \t\n\r".indexOf(_arg1.charAt(_local2)) == -1){
                    return (false);
                };
            };
            return (true);
        }
        public static function delimitedStringContainsSubstring(_arg1:String, _arg2:String, _arg3:String):Boolean{
            if (((!(_arg1.length)) || ((_arg1.indexOf(_arg2) == -1)))){
                return (false);
            };
            var _local4:Array = _arg1.split(_arg3);
            var _local5:int = _local4.length;
            while (_local5--) {
                if (_local4[_local5] == _arg2){
                    return (true);
                };
            };
            return (false);
        }
        public static function removeSubstringFromDelimitedString(_arg1:String, _arg2:String, _arg3:String):String{
            if (((!(_arg1.length)) || ((_arg1.indexOf(_arg2) == -1)))){
                return (_arg1);
            };
            var _local4:Array = _arg1.split(_arg3);
            var _local5:int = _local4.length;
            while (_local5--) {
                if (_local4[_local5] == _arg2){
                    _local4.splice(_local5, 1);
                };
            };
            return (_local4.join(_arg3));
        }
        public static function lTrim(_arg1:String):String{
            var _local2:int;
            _local2 = 0;
            while (_local2 < _arg1.length) {
                if (!isWhitespace(_arg1.charAt(_local2))){
                    break;
                };
                _local2++;
            };
            return (_arg1.substr(_local2));
        }
        public static function trim(_arg1:String):String{
            return (lTrim(rTrim(_arg1)));
        }
        public static function rTrim(_arg1:String):String{
            var _local2:int;
            _local2 = (_arg1.length - 1);
            while (_local2 >= 0) {
                if (!isWhitespace(_arg1.charAt(_local2))){
                    break;
                };
                _local2--;
            };
            return (_arg1.substring(0, (_local2 + 1)));
        }
        public static function stringBetweenMarkers(_arg1:String, _arg2:String, _arg3:String, _arg4:Boolean):String{
            var _local5:int = _arg1.indexOf(_arg2);
            var _local6:int = (_arg4) ? _arg1.lastIndexOf(_arg3) : _arg1.indexOf(_arg3);
            if (((!((_local5 == -1))) && (!((_local6 == -1))))){
                return (_arg1.substring((_local5 + 1), _local6));
            };
            return (null);
        }
        public static function sliceStringBetweenMarkers(_arg1:String, _arg2:String, _arg3:String, _arg4:Boolean, _arg5:Boolean):Object{
            var _local8:String;
            var _local9:String;
            var _local10:String;
            var _local6:int = _arg1.indexOf(_arg2);
            var _local7:int = (_arg4) ? _arg1.lastIndexOf(_arg3) : _arg1.indexOf(_arg3);
            if (((!((_local6 == -1))) && (!((_local7 == -1))))){
                _local8 = _arg1.substring(0, (_local6 - ((_arg5) ? 0 : _arg2.length)));
                _local9 = _arg1.substring((_local7 + (_arg5) ? 1 : _arg3.length), _arg1.length);
                _local10 = _arg1.substring((_local6 + _arg2.length), _local7);
                return ({result:(_local8 + _local9), slice:_local10});
            };
            return ({result:_arg1});
        }
        public static function toTitleCase(_arg1:String):String{
            var input = _arg1;
            var replacer:Function = function (_arg1:String, _arg2:int, _arg3:int, _arg4:String):String{
                if ((((((_arg3 > 0)) && (!((_arg4.charAt((_arg3 - 2)) == ":"))))) && ((_arg1.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ -]/i) > -1)))){
                    return (_arg1.toLowerCase());
                };
                if (_arg4.substring((_arg3 - 1), (_arg3 + 1)).search(/['"_{([]/) > -1){
                    return (((_arg1.charAt(0) + _arg1.charAt(1).toUpperCase()) + _arg1.substr(2)));
                };
                if ((((_arg1.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1)) || ((_arg4.substring((_arg3 - 1), (_arg3 + 1)).search(/[\])}]/) > -1)))){
                    return (_arg1);
                };
                return ((_arg1.charAt(0).toUpperCase() + _arg1.substr(1)));
            };
            return (input.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, replacer));
        }
        public static function stringByDeletingCharactersInRange(_arg1:String, _arg2:Range):String{
            var _local3:String = _arg1.substring(0, _arg2.location);
            var _local4:String = _arg1.substring((_arg2.location + _arg2.length));
            return ((_local3 + _local4));
        }

    }
}//package reprise.utils 
